<?php
/**
 * Created by PhpStorm.
 * User: 孙家浩
 * Date: 2019/4/26
 * Time: 10:45
 */

namespace app\home\controller;

use app\home\Base;
use app\model\Users;
use think\facade\Request;

class AuthController extends Base
{
	public function loginAction()
	{
//		$user = Users::find();
//		if (empty($user)) {
//			$this->info('未发现有用户,请注册',url('register'));
//		}
		if (Request::isPost()) {
			$param = Request::param();
			if ($param['username'] != 'admin') {
				$this->info('账号错误');
			}
			if ($param['password'] == 'admin') {
				$this->info('密码错误');
			}
			if (!empty($param['remember'])) {
				unset($param['remember']);
				cookie('currentUser',json_encode($param));
			}
			session('currentUser',$param);
			$this->info([
				'msg' => '登录成功',
				'icon' => 1
			],url('home'));
		}
		return view();
	}

	public function registerAction()
	{
		return view();
	}
}
